//
//  CCNodeUpdater.m
//  Prism
//
//  Created by Bas du Pre on 21-05-11.
//  Copyright 2011 UU. All rights reserved.
//

#include "global.h"
#if PRISM_OS_IOS

#import "CCNodePrism.h"

@implementation CCNode (CCNodePrism)

-(void) setPrismNode:(NSValue*)node {
    self.userData = [node pointerValue];
}

-(Prism::Node*) getPrismNode {
    return (Prism::Node*)self.userData;
}

-(void) prismUpdate:(ccTime)delta {
    Prism::UpdateEventArgs e(delta);
    ((Prism::Node*)self.userData)->onUpdate(self.userData, &e);
}

-(void) visit
{
    // Prism doesn't use the zOrder of Cocos, so it has to be ignored in visit.
    
	// quick return if not visible
	if (!visible_)
		return;
	
	glPushMatrix();
	
	if ( grid_ && grid_.active) {
		[grid_ beforeDraw];
		[self transformAncestors];
	}
    
	[self transform];
	
	/*if(children_) {
		ccArray *arrayData = children_->data;
		NSUInteger i = 0;
		
		// draw children zOrder < 0
		for( ; i < arrayData->num; i++ ) {
			CCNode *child = arrayData->arr[i];
			if ( [child zOrder] < 0 )
				[child visit];
			else
				break;
		}
		
		// self draw
		[self draw];
		
		// draw children zOrder >= 0
		for( ; i < arrayData->num; i++ ) {
			CCNode *child =  arrayData->arr[i];
			[child visit];
		}
        
	} else*/
    
    [self draw];
	
	if ( grid_ && grid_.active)
		[grid_ afterDraw:self];
	
	glPopMatrix();
}


@end

#endif